package cn.tedu.imop.marketing.controller;


import cn.tedu.imop.api.model.RestResult;
import cn.tedu.imop.api.model.RestResultUtils;
import cn.tedu.imop.common.constants.Constants;
import cn.tedu.imop.common.pojo.PageData;
import cn.tedu.imop.marketing.entity.Coupon;
import cn.tedu.imop.marketing.entity.MemberCoupon;
import cn.tedu.imop.marketing.service.MemberCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags="会员优惠卷")
@RestController
@RequestMapping(Constants.CONTROLLER_API_VERSION+"/member/coupon")
public class MemberCouponController {
    private final MemberCouponService memberCouponService;
    public MemberCouponController(MemberCouponService memberCouponService) {
        this.memberCouponService = memberCouponService;
    }
    //领取优惠劵(向会员优惠卷表中写入一条记录)
    @ApiOperation("领取优惠卷")
    @PostMapping
    public RestResult<Void> createCoupon(MemberCoupon memberCoupon) {//activityId，couponId，couponCode
         memberCouponService.createMemberCoupon(memberCoupon);
         return RestResultUtils.success();
    }
     //分页查看我的优惠卷
    @ApiOperation("我的优惠卷")
    @GetMapping
    public RestResult<PageData<Coupon>> getCouponList(Integer status) {
         //判断用户是否已认证(登录，没有登录需要先登录)
         Integer memberId=1;
         //根据用户id查询优惠卷列表
         PageData<MemberCoupon> memberCouponPageData =
                 memberCouponService.getMemberCouponList(1, status);
         return RestResultUtils.success();
    }
    //查看优惠卷的二维码
    @ApiOperation("优惠卷详情")
    @GetMapping("/qrcode")
    public RestResult<String> getCouponQrcode(Integer couponId) {
         //判断用户是否已认证(登录，没有登录需要先登录)
         //根据优惠卷id查询优惠卷信息
        MemberCoupon memberCoupon =
                memberCouponService.getMemberCouponById(couponId);
        return RestResultUtils.success(memberCoupon==null?"":memberCoupon.getCouponCode());
    }

}
